package com.yaorange.nongjt.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yaorange.common.annotation.Log;
import com.yaorange.common.core.controller.BaseController;
import com.yaorange.common.core.domain.AjaxResult;
import com.yaorange.common.enums.BusinessType;
import com.yaorange.nongjt.domain.NjtCertificatePrint;
import com.yaorange.nongjt.service.INjtCertificatePrintService;
import com.yaorange.common.utils.poi.ExcelUtil;
import com.yaorange.common.core.page.TableDataInfo;

/**
 * 合格证打印Controller
 * 
 * @author Mmj
 * @date 2025-02-28
 */
@RestController
@RequestMapping("/nongjt/print")
public class NjtCertificatePrintController extends BaseController
{
    @Autowired
    private INjtCertificatePrintService njtCertificatePrintService;

    /**
     * 查询合格证打印列表
     */
    @PreAuthorize("@ss.hasPermi('nongjt:print:list')")
    @GetMapping("/list")
    public TableDataInfo list(NjtCertificatePrint njtCertificatePrint)
    {
        startPage();
        List<NjtCertificatePrint> list = njtCertificatePrintService.selectNjtCertificatePrintList(njtCertificatePrint);
        return getDataTable(list);
    }

    /**
     * 导出合格证打印列表
     */
    @PreAuthorize("@ss.hasPermi('nongjt:print:export')")
    @Log(title = "合格证打印", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NjtCertificatePrint njtCertificatePrint)
    {
        List<NjtCertificatePrint> list = njtCertificatePrintService.selectNjtCertificatePrintList(njtCertificatePrint);
        ExcelUtil<NjtCertificatePrint> util = new ExcelUtil<NjtCertificatePrint>(NjtCertificatePrint.class);
        util.exportExcel(response, list, "合格证打印数据");
    }

    /**
     * 获取合格证打印详细信息
     */
    @PreAuthorize("@ss.hasPermi('nongjt:print:query')")
    @GetMapping(value = "/{mobilePhone}")
    public AjaxResult getInfo(@PathVariable("mobilePhone") String mobilePhone)
    {
        return success(njtCertificatePrintService.selectNjtCertificatePrintByMobilePhone(mobilePhone));
    }

    /**
     * 新增合格证打印
     */
    @PreAuthorize("@ss.hasPermi('nongjt:print:add')")
    @Log(title = "合格证打印", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NjtCertificatePrint njtCertificatePrint)
    {
        return toAjax(njtCertificatePrintService.insertNjtCertificatePrint(njtCertificatePrint));
    }

    /**
     * 修改合格证打印
     */
    @PreAuthorize("@ss.hasPermi('nongjt:print:edit')")
    @Log(title = "合格证打印", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NjtCertificatePrint njtCertificatePrint)
    {
        return toAjax(njtCertificatePrintService.updateNjtCertificatePrint(njtCertificatePrint));
    }

    /**
     * 删除合格证打印
     */
    @PreAuthorize("@ss.hasPermi('nongjt:print:remove')")
    @Log(title = "合格证打印", businessType = BusinessType.DELETE)
	@DeleteMapping("/{mobilePhones}")
    public AjaxResult remove(@PathVariable String[] mobilePhones)
    {
        return toAjax(njtCertificatePrintService.deleteNjtCertificatePrintByMobilePhones(mobilePhones));
    }
}
